<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文章管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i>栏目列表(排除外部链接)
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand"
                        title="展开" style="display: none;">
                    <i class="fa fa-chevron-up"></i>
                </button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse"
                        title="折叠">
                    <i class="fa fa-chevron-down"></i>
                </button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh"
                        title="刷新栏目列表">
                    <i class="fa fa-refresh"></i>
                </button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="article-form">
                    <input type="hidden" id="columnId" name="columnId">
                    <div class="select-list">
                        <ul>
                            <li>
                                文章标题：<input type="text" name="title"/>
                            </li>
                            <li>
                                <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="'cms:article:add'">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()"
                   shiro:hasPermission="'cms:article:edit'">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="'cms:article:remove'">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + "cms/article";
    var columnPrefix = ctx + "cms/column";
    var datas = [[${@dict.getType('cms_show_hide')}]];
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 250});
        //查询栏目树
        queryColumnTree();
        //查询文章内容列表
        queryArticleList();
    });

    /* 	左侧树  begin */
    function queryColumnTree() {
        var url = columnPrefix + "/columnTreeData?outLink=1";//不是外部链接
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        //左侧树，点击树节点触发事件
        function zOnClick(event, treeId, treeNode) {
            $("#columnId").val(treeNode.id);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });
    // 刷新栏目列表
    $('#btnRefresh').click(function () {
        //置空栏目id
        $("#columnId").val("");
        //刷新左侧栏目树
        queryColumnTree();
        //刷新右侧表格
        $.table.search();
    });
    /* 左侧树	end */

    //新增
    function add(){
        var columnId=$("#columnId").val();
        $.operate.addFull(columnId);
    }


    /* 右侧表格	begin */
    function queryArticleList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add?id={id}",
            updateUrl: prefix + "/edit?id={id}",
            removeUrl: prefix + "/remove",
            modalName: "文章列表",
            /* 翻页记住选中 */
            rememberSelected: true,
            columns: [{
                field: 'state',
                checkbox: true
            },
                {
                    field: 'id',
                    visible: false,
                    title: '编号'
                },
                {
                    field: 'columnName',
                    title: '所属栏目'
                },
                {
                    field: 'columnFlag',
                    title: '栏目标识'
                },
                {
                    field: 'title',
                    title: '文章标题',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'description',
                    title: '摘要',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'imageName',
                    title: '缩略图名称',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'imageUrl',
                    title: '缩略图',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'sort',
                    title: '排序'
                },
                {
                    field: 'status',
                    title: '显示状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateBy',
                    title: '更新人'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    /* 右侧表格	end */
</script>
</body>
</html>